import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 98152
 * Date: 2024-10-17
 * Time: 20:19
 */
public class Test1 {
    public static int left = 0;
    public static int right = 1;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        fibNum(n);
        int minStep = Math.min(n-left, right-n);
        System.out.println(minStep);
    }
    private static void fibNum(int n) {
        int num1 = 0;
        int num2 = 1;
        for(int i = 1; !(left <= n && right >= n); i++) {
            int tmp = num1;
            num1 = num2;
            num2 = num2 + tmp;

            left = num1;
            right = num2;
        }
    }
}
